package hot100.logos1To10;

/**
 * @author logos
 * date 2025/7/9 20:57
 * @version v1.0
 * @Package hot100
 */
public class logos8 {

    /**
     * 8.无重复字符的最长子串
     * https://leetcode.cn/problems/longest-substring-without-repeating-characters/?envType=study-plan-v2&envId=top-100-liked
     */

    class Solution {
        public int lengthOfLongestSubstring(String s) {
            int[] map = new int[256];
            char[] sArr = s.toCharArray();
            int ans = 0;
            for (int left = 0, right = 0; right < sArr.length; right++) {
                map[sArr[right]]++;
                while (map[sArr[right]] > 1) {
                    map[sArr[left]]--;
                    left++;
                }
                ans = Math.max(ans, right - left + 1);
            }
            return ans;
        }
    }
}
